package com.api.controller.log;

import com.api.annotation.AuthToken;
import com.api.controller.BaseController;
import com.api.pojo.User;
import com.api.service.BaseService;
import com.api.service.log.LogUserService;
import com.api.util.AjaxResult;
import com.api.util.MapUtil;
import com.api.util.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @packageName: com.api.controller.log
 * @name: LogUserController
 * @description:
 * @author: 董定卓
 * @dateTime: 2019/6/20 15:15
 */
@RestController
@RequestMapping("/logUser")
public class LogUserController extends BaseController {

    @Autowired
    LogUserService service;

    @Override
    protected BaseService getService() {
        return service;
    }

    /**
     * 用户日志分页列表
     *
     * @param map
     * @param limit
     * @param page
     * @return
     */
    @PostMapping("/page")
    @Override
    @AuthToken
    public AjaxResult page(@RequestParam Map<String, Object> map, @RequestParam(value = "limit", defaultValue = "10") int limit, @RequestParam(value = "page", defaultValue = "1") int page) {
        String startDay = MapUtil.getString(map, "startDay");
        String endDay = MapUtil.getString(map, "endDay");
        if (startDay != null) {
            map.put("startDay", startDay.replaceAll("-", ""));
        }
        if (endDay != null) {
            map.put("endDay", endDay.replaceAll("-", ""));
        }
        User userDetail = UserUtil.getUserDetail();
        Integer userId = userDetail.getId();
        if (!"1".equals(userId.toString())) {
            map.put("userId", userId);
        }
        return super.page(map, limit, page);
    }
}
